import java.io.*;
import java.util.Scanner;

public class demo2 {
    /**
     * 复制文件
     * @param args
     */
    public static void main(String[] args) {
        //1.输入路径，并且做校验
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入源文件的路径");
        String srcPath = sc.nextLine();
        File srcFile = new File(srcPath);
        if (!srcFile.isFile()) {
            System.out.println("源文件路径不存在");
            return;
        }

        System.out.println("请输入目标文件的路径");
        String destPath = sc.nextLine();
        File destFile = new File(destPath);
        if (!destFile.getParentFile().isDirectory()) {
            System.out.println("目标文件路径不存在");
            return;
        }

        //2.执行复制过程
        try (InputStream inputStream = new FileInputStream(srcFile);
             OutputStream outputStream = new FileOutputStream(destFile)) {
            while(true){
                byte[] buffer=new byte[1024];
                int n=inputStream.read(buffer);
                if(n==-1){
                    break;
                }
                outputStream.write(buffer,0,n);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("复制文件完成");
    }
}
